#include "QueryPlanNode.h"

ProjectNode::ProjectNode(int inPipeId, int outPipeId, vector<int> *keepMe,
		int numAttsInput, int numAttsOutput, Pipe *inPipe, Pipe *outPipe) : QueryPlanNode(project),
		inPipeId(inPipeId), outPipeId(outPipeId), keepMe(keepMe), numAttsInput(
		numAttsInput), numAttsOutput(numAttsOutput), inPipe(inPipe), outPipe(outPipe){

    keepMeInt = new int();
    int c = 0;
	for (vector<int>::iterator it = keepMe->begin(); it != keepMe->end(); it++)
	{
	    keepMeInt[c] = *it;
	    c++;
	}

}

void ProjectNode::Print(){
	cout<<"********\n";
	cout<<"Project\n";
	cout<<"Input pipe ID "<<inPipeId<<endl;
	cout<<"Output pipe ID "<<outPipeId<<endl;
	cout<<"Projected Attributes:\n";
	for (int i = 0; i < numAttsOutput; i++)
		cout<<keepMeInt[i]<<" ";
	cout<<endl;
	cout<<"********\n";
}

void ProjectNode::Execute(){
	pro.Use_n_Pages(RUN_LENGTH);
	pro.Run(*inPipe, *outPipe, keepMeInt, numAttsInput, numAttsOutput);
}

void ProjectNode::Wait(){
	pro.WaitUntilDone();
}

void ProjectNode::Clean(){
    delete inPipe, outPipe, out_pipe;
}
